home *** CD-ROM | disk | FTP | other *** search
- package com.opera;
-
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.Enumeration;
-
- public class OperaURLConnection extends HttpURLConnection {
- // $FF: renamed from: is com.opera.OperaInputStream
- private OperaInputStream field_0 = new OperaInputStream();
- private int istream_id;
- // $FF: renamed from: os com.opera.OperaOutputStream
- private OperaOutputStream field_1 = new OperaOutputStream();
- private int ostream_id;
-
- protected OperaURLConnection(URL var1) {
- super(var1);
- this.istream_id = OperaInputStream.addStream(this.field_0);
- this.ostream_id = OperaOutputStream.addStream(this.field_1);
- this.field_1.istream_id = this.istream_id;
- }
-
- public void connect() throws IOException {
- if (!this.connected) {
- String var1 = this.url.toString();
- if (this.url.getPort() == -1) {
- int var2 = var1.indexOf(":-1");
- if (var2 != -1) {
- StringBuffer var3 = new StringBuffer(var1);
- var3.delete(var2, var2 + 3);
- var1 = var3.toString();
- }
- }
-
- SecurityManager var14 = System.getSecurityManager();
- if (var14 != null) {
- var14.checkConnect(this.url.getHost(), this.url.getPort());
- }
-
- try {
- if (this.method.compareTo("POST") == 0) {
- synchronized(PluginContext.opera_mutex) {
- this.nativeConnect(var1, this.method, this.ostream_id);
- this.ostream_id = -1;
- this.istream_id = -1;
- }
-
- this.connected = true;
- } else if (this.method.compareTo("GET") == 0) {
- synchronized(PluginContext.opera_mutex) {
- this.nativeConnect(var1, this.method, this.istream_id);
- this.ostream_id = -1;
- this.istream_id = -1;
- }
-
- try {
- synchronized(this.field_0) {
- if (!this.field_0.isHeaderLoaded()) {
- this.field_0.wait();
- }
- }
- } catch (InterruptedException var10) {
- Thread.currentThread().interrupt();
- }
-
- this.responseCode = this.field_0.getResponse();
- if (this.responseCode != 200) {
- this.connected = false;
- } else {
- this.connected = true;
- }
- } else {
- synchronized(this.field_0) {
- this.field_0.headerLoaded(0, 200);
- this.field_0.setEOF();
- }
-
- this.connected = true;
- }
- } catch (Exception var13) {
- var13.printStackTrace(System.err);
- }
-
- if (!this.connected) {
- throw new IOException("Connection failed.");
- }
- }
-
- }
-
- private native void nativeConnect(String var1, String var2, int var3);
-
- public InputStream getInputStream() throws IOException {
- if (!this.connected) {
- this.connect();
- }
-
- if (this.method.compareTo("POST") == 0) {
- if (!this.field_1.isClosed()) {
- this.field_1.close();
- }
-
- if (this.field_0.getResponse() == -1) {
- try {
- synchronized(this.field_0) {
- this.field_0.wait();
- }
- } catch (InterruptedException var4) {
- Thread.currentThread().interrupt();
- }
- }
-
- if (this.field_0.getResponse() != 200) {
- this.connected = false;
- throw new FileNotFoundException(this.url.toString());
- }
-
- this.connected = true;
- }
-
- return this.field_0;
- }
-
- public String getContentType() {
- return this.getHeaderField("content-type");
- }
-
- public int getContentLength() {
- if (!this.connected) {
- try {
- this.connect();
- } catch (Exception var2) {
- }
- }
-
- return this.field_0 != null ? this.field_0.getContentLength() : 0;
- }
-
- public String getContentEncoding() {
- return this.getHeaderField("content-encoding");
- }
-
- public OutputStream getOutputStream() throws IOException {
- this.method = "POST";
- if (!this.connected) {
- this.connect();
- }
-
- return this.field_1;
- }
-
- public int getHeaderFieldInt(String var1, int var2) {
- String var3 = this.getHeaderField(var1);
- if (var3 != null) {
- try {
- return Integer.parseInt(var3);
- } catch (NumberFormatException var5) {
- }
- }
-
- return var2;
- }
-
- public String getHeaderField(int var1) {
- if (!this.connected) {
- try {
- this.connect();
- } catch (Exception var4) {
- return null;
- }
- }
-
- this.waitForHeaderLoaded();
-
- for(Enumeration var2 = this.field_0.header_fields.elements(); var1 > 0 && var2.hasMoreElements(); --var1) {
- Object var3 = var2.nextElement();
- if (var1 == 1) {
- return (String)var3;
- }
- }
-
- return null;
- }
-
- public String getHeaderFieldKey(int var1) {
- if (!this.connected) {
- try {
- this.connect();
- } catch (Exception var4) {
- return null;
- }
- }
-
- this.waitForHeaderLoaded();
-
- for(Enumeration var2 = this.field_0.header_fields.keys(); var1 > 0 && var2.hasMoreElements(); --var1) {
- Object var3 = var2.nextElement();
- if (var1 == 1) {
- return (String)var3;
- }
- }
-
- return null;
- }
-
- public String getHeaderField(String var1) {
- if (!this.connected) {
- try {
- this.connect();
- } catch (Exception var3) {
- return null;
- }
- }
-
- this.waitForHeaderLoaded();
- return (String)this.field_0.header_fields.get(var1.toLowerCase());
- }
-
- public String getRequestProperty(String var1) {
- return (String)this.field_1.req_props.get(var1);
- }
-
- public void setRequestProperty(String var1, String var2) {
- if (var1.compareToIgnoreCase("Content-length") != 0) {
- this.field_1.req_props.put(var1, var2);
- }
-
- }
-
- public void disconnect() {
- }
-
- public boolean usingProxy() {
- return false;
- }
-
- public int getResponseCode() throws IOException {
- if (!this.connected) {
- this.connect();
- }
-
- try {
- synchronized(this.field_0) {
- if (!this.field_0.isHeaderLoaded()) {
- this.field_0.wait();
- this.responseCode = this.field_0.getResponse();
- }
- }
- } catch (InterruptedException var4) {
- Thread.currentThread().interrupt();
- }
-
- return this.responseCode;
- }
-
- protected void finalize() throws Throwable {
- if (this.istream_id != -1) {
- OperaInputStream.removeStream(this.istream_id);
- }
-
- super.finalize();
- }
-
- protected void waitForHeaderLoaded() {
- try {
- synchronized(this.field_0) {
- if (!this.field_0.isHeaderLoaded()) {
- this.field_0.wait();
- }
- }
- } catch (InterruptedException var4) {
- Thread.currentThread().interrupt();
- }
-
- }
- }
-